﻿package mortal.game.view.task.data
{
    import Message.Public.*;
    import extend.language.*;
    import flash.utils.*;

    public class TaskRule extends Object
    {
        private static var _taskGroupFullName:Dictionary;
        private static var _taskGroupShortName:Dictionary;
        private static var _taskGroupTitle:Array;
        private static var _taskGroupSortCompletedRule:Array;
        private static var _taskGroupSortNotCompletedRule:Array;
        private static var _taskGroupSortNormalRule:Array = [ETaskGroup._ETaskGroupMain, ETaskGroup._ETaskGroupBranch, ETaskGroup._ETaskGroupLoop, ETaskGroup._ETaskGroupEscort, ETaskGroup._ETaskGroupGuild, ETaskGroup._ETaskGroupMinning, ETaskGroup._ETaskGroupAutoFight, ETaskGroup._ETaskGroupSpy, ETaskGroup._ETaskGroupRomance, ETaskGroup._ETaskGroupTreasure, ETaskGroup._ETaskGroupGuildCreate, ETaskGroup._ETaskGroupCopy, ETaskGroup._ETaskGroupPvp, ETaskGroup._ETaskGroupCross];
        private static var ia:int;
        private static var ib:int;

        public function TaskRule()
        {
            return;
        }// end function

        public static function getGroupTotalTimes(param1:int) : int
        {
            switch(param1)
            {
                case ETaskGroup._ETaskGroupGuild:
                {
                    return 10;
                }
                case ETaskGroup._ETaskGroupLoop:
                {
                    return 20;
                }
                case ETaskGroup._ETaskGroupPvp:
                {
                    return 3;
                }
                case ETaskGroup._ETaskGroupEscort:
                {
                    return 3;
                }
                default:
                {
                    break;
                }
            }
            return 1;
        }// end function

        private static function initGroupFullName() : void
        {
            _taskGroupFullName = new Dictionary();
            _taskGroupFullName[ETaskGroup._ETaskGroupMain] = Language.getString(20126);
            _taskGroupFullName[ETaskGroup._ETaskGroupBranch] = Language.getString(20127);
            _taskGroupFullName[ETaskGroup._ETaskGroupLoop] = Language.getString(20128);
            _taskGroupFullName[ETaskGroup._ETaskGroupEscort] = Language.getString(20129);
            _taskGroupFullName[ETaskGroup._ETaskGroupRobEscort] = Language.getString(20266);
            _taskGroupFullName[ETaskGroup._ETaskGroupGuild] = Language.getString(21162);
            _taskGroupFullName[ETaskGroup._ETaskGroupTreasure] = Language.getString(20131);
            _taskGroupFullName[ETaskGroup._ETaskGroupCopy] = Language.getString(20132);
            _taskGroupFullName[ETaskGroup._ETaskGroupRomance] = Language.getString(20133);
            _taskGroupFullName[ETaskGroup._ETaskGroupSpy] = Language.getString(20134);
            _taskGroupFullName[ETaskGroup._ETaskGroupCross] = Language.getString(20135);
            _taskGroupFullName[ETaskGroup._ETaskGroupGuildCreate] = Language.getString(21163);
            _taskGroupFullName[ETaskGroup._ETaskGroupAutoFight] = Language.getString(21164);
            _taskGroupFullName[ETaskGroup._ETaskGroupPvp] = Language.getString(21165);
            _taskGroupFullName[ETaskGroup._ETaskGroupMinning] = Language.getString(21166);
            return;
        }// end function

        private static function initGroupShortName() : void
        {
            var _loc_1:* = Language.getString(20145).split(",");
            _taskGroupShortName = new Dictionary();
            _taskGroupShortName[ETaskGroup._ETaskGroupMain] = _loc_1[0];
            _taskGroupShortName[ETaskGroup._ETaskGroupBranch] = _loc_1[1];
            _taskGroupShortName[ETaskGroup._ETaskGroupLoop] = _loc_1[2];
            _taskGroupShortName[ETaskGroup._ETaskGroupEscort] = _loc_1[3];
            _taskGroupShortName[ETaskGroup._ETaskGroupGuild] = _loc_1[4];
            _taskGroupShortName[ETaskGroup._ETaskGroupTreasure] = _loc_1[5];
            _taskGroupShortName[ETaskGroup._ETaskGroupCopy] = _loc_1[6];
            _taskGroupShortName[ETaskGroup._ETaskGroupRomance] = _loc_1[7];
            _taskGroupShortName[ETaskGroup._ETaskGroupSpy] = _loc_1[8];
            _taskGroupShortName[ETaskGroup._ETaskGroupCross] = _loc_1[9];
            _taskGroupShortName[ETaskGroup._ETaskGroupAutoFight] = Language.getString(21167);
            _taskGroupShortName[ETaskGroup._ETaskGroupPvp] = "PVP";
            _taskGroupShortName[ETaskGroup._ETaskGroupMinning] = Language.getString(21168);
            return;
        }// end function

        public static function getTaskGroupTitleMap() : Array
        {
            if (!_taskGroupTitle)
            {
                _taskGroupTitle = [{label:Language.getString(20126), type:ETaskGroup._ETaskGroupMain}, {label:Language.getString(20127), type:ETaskGroup._ETaskGroupBranch}, {label:Language.getString(20128), type:ETaskGroup._ETaskGroupLoop}, {label:Language.getString(20129), type:ETaskGroup._ETaskGroupEscort}, {label:Language.getString(20266), type:ETaskGroup._ETaskGroupRobEscort}, {label:Language.getString(21162), type:ETaskGroup._ETaskGroupGuild}, {label:Language.getString(20131), type:ETaskGroup._ETaskGroupTreasure}, {label:Language.getString(20132), type:ETaskGroup._ETaskGroupCopy}, {label:Language.getString(20133), type:ETaskGroup._ETaskGroupRomance}, {label:Language.getString(20134), type:ETaskGroup._ETaskGroupSpy}, {label:Language.getString(20135), type:ETaskGroup._ETaskGroupCross}, {label:Language.getString(20127), type:ETaskGroup._ETaskGroupGuildCreate}, {label:Language.getString(21167), type:ETaskGroup._ETaskGroupAutoFight}, {label:Language.getString(21165), type:ETaskGroup._ETaskGroupPvp}, {label:Language.getString(21166), type:ETaskGroup._ETaskGroupMinning}];
            }
            return _taskGroupTitle;
        }// end function

        public static function sortTaskByPriority(param1:TaskInfo, param2:TaskInfo) : int
        {
            if (param1.stask.group == ETaskGroup._ETaskGroupMain)
            {
                return -1;
            }
            if (param2.stask.group == ETaskGroup._ETaskGroupMain)
            {
                return 1;
            }
            if (param1.isDoing() && param2.isCanget())
            {
                return -1;
            }
            if (param1.isCanget() && param2.isDoing())
            {
                return 1;
            }
            ia = _taskGroupSortNormalRule.indexOf(param1.stask.group);
            ib = _taskGroupSortNormalRule.indexOf(param2.stask.group);
            if (ia <= ib)
            {
                return -1;
            }
            return 1;
        }// end function

        public static function sortTask(param1:TaskInfo, param2:TaskInfo) : int
        {
            if (param1.status < param2.status)
            {
                return 1;
            }
            if (param1.status > param2.status)
            {
                return -1;
            }
            ia = _taskGroupSortNormalRule.indexOf(param1.stask.group);
            if (ia < 0)
            {
                return 1;
            }
            ib = _taskGroupSortNormalRule.indexOf(param2.stask.group);
            if (ib < 0)
            {
                return -1;
            }
            if (ia < ib)
            {
                return -1;
            }
            if (ia > ib)
            {
                return 1;
            }
            if (param1.stask.code <= param2.stask.code)
            {
                return -1;
            }
            return 1;
        }// end function

        public static function getGroupShortName(param1:int) : String
        {
            if (!_taskGroupShortName)
            {
                initGroupShortName();
            }
            return _taskGroupShortName[param1];
        }// end function

        public static function getGroupFullName(param1:int) : String
        {
            if (!_taskGroupFullName)
            {
                initGroupFullName();
            }
            return _taskGroupFullName[param1];
        }// end function

        public static function shouldShowTaskFunc(param1:Array) : Boolean
        {
            var _loc_2:TaskInfo = null;
            if (param1 == null || param1.length == 0)
            {
                return true;
            }
            if (param1.length == 1)
            {
                _loc_2 = param1[0];
                if (_loc_2 == null)
                {
                    return true;
                }
                if (!_loc_2.isCanget() && _loc_2.stask.group == ETaskGroup._ETaskGroupEscort)
                {
                    return false;
                }
                switch(_loc_2.stask.group)
                {
                    case ETaskGroup._ETaskGroupMinning:
                    case ETaskGroup._ETaskGroupEscort:
                    {
                        return true;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return false;
        }// end function

        public static function isNotAutoShowNextTask(param1:TaskInfo) : Boolean
        {
            if (param1 == null)
            {
                return true;
            }
            if (param1.isCanNotEnd())
            {
                return true;
            }
            var _loc_2:* = param1.stask.group;
            if (_loc_2 == ETaskGroup._ETaskGroupMinning)
            {
                return true;
            }
            if (_loc_2 == ETaskGroup._ETaskGroupAutoFight)
            {
                return true;
            }
            if (_loc_2 == ETaskGroup._ETaskGroupGuild && param1.isDoing())
            {
                return true;
            }
            return false;
        }// end function

    }
}
